package org.myproject.util;

import org.hibernate.proxy.HibernateProxy;

/**
 * Hibernate utilities
 * 
 * @author ivaynberg
 * 
 */
public class HibernateUtils {
	private HibernateUtils() {

	}

	/**
	 * Unwraps entity if it is wrapped in a hibernate proxy
	 * 
	 * @param entity
	 * @return unwrapped entity
	 */
	public static Object unproxy(Object entity) {
		if (entity instanceof HibernateProxy) {
			return ((HibernateProxy) entity).getHibernateLazyInitializer()
					.getImplementation();
		} else {
			return entity;
		}
	}
}
